package com.hnu.java.test.tracfic;



public enum Lamp {

	S2N("N2S","S2W",false),S2W("N2E","E2W",false),E2W("W2E","E2S",false),E2S("W2N","S2N",false),
	N2S(null,null,false),N2E(null,null,false),W2E(null,null,false),W2N(null,null,false),
	S2E(null,null,true),E2N(null,null,true),N2W(null,null,true),W2S(null,null,true);
	
	/*S2N("N2S","S2W",false),S2W("N2E","E2W",false),E2W("W2E","E2S",false),E2S("W2N","S2N",false),
	下面元素表示与上面的元素的相反方向的灯，它们的“相反方向灯”和“下一个灯”应忽略不计！
	N2S(null,null,false),N2E(null,null,false),W2E(null,null,false),W2N(null,null,false),
	由南向东和由西向北等右拐弯的灯不受红绿灯的控制，所以，可以假想它们总是绿灯
	S2E(null,null,true),E2N(null,null,true),N2W(null,null,true),W2S(null,null,true);*/
	
	private boolean lighted = false;
	private String opposite;
	private String nextLamp;
	 Lamp(String opposite,String nextLamp,boolean isLighted){
		this.opposite=opposite;
		this.nextLamp=nextLamp;
		this.lighted=isLighted;
	}
	public boolean isLight(){
		return lighted;
	}
	
	public void light()
	{
		this.lighted=true;
		if(this.opposite!=null){
			Lamp.valueOf(opposite).light();
			System.out.println(name() +"is green ,you can see six roads is tracfficing");
		}
		
	}
	
	public Lamp blackOut(){
		
		this.lighted=false;
		if(this.opposite!=null){
			Lamp.valueOf(opposite).blackOut();
		}
		Lamp next = null;
		if(nextLamp!=null){
			next = Lamp.valueOf(nextLamp);
			System.out.println("绿灯从"+ name()+"变为"+nextLamp);
			next.light();
		}
		return next;
	}
}
